package com.gxgeek.redis.application.redistool;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisCommands;
import redis.clients.jedis.JedisPool;

import java.io.Serializable;

/**
 * @author gaoxing
 * @create 2017-09-26 下午3:30
 */
public class JedisUtils {

    public static JedisCommands getJedisCommands(JedisCluster jedisCluster, JedisPool jedisPool) {
        JedisCommands commands = null;
        if (jedisCluster == null) {
            Jedis jedis = jedisPool.getResource();
            commands = jedis;
        } else {
            commands = jedisCluster;
        }
        return commands;
    }

    public static void releaseJedisConnection(JedisCommands commands) {
        if (commands != null && commands instanceof Jedis) {
            Jedis jedis = (Jedis) commands;
            jedis.close();
        }
    }

}
